<?php
class CacheServer extends Object{
    protected $_options=null;
    
    public function __construct($options=null){
        $this->CacheServer($options);
    }
    
    private function cacheServer($options=NULL){
        $this->_options=$options;
    }
    
    private function &get($key){
        #TODO
    }
    
    
    private function set($key,$value,$ttl=0){}
    
    private function clear(){}
    
    private function delete($key){}


}



//普通文件缓存类
class PhpCacheServer extends CacheServer{
    #TODO 文件缓存暂时不做
}


/*
 * memcache缓存类
 * */
class MemcacheServer extends CacheServer{
    private $_memcache=null;
    
    public function __construct($options){
        $this->MemcacheServer($options);    
    }
    
    private function MemcacheServer($options){
        parent::__construct($options);
        $this->connect($this->_options);
    }
    
    private function connect($options){
        if (empty($options))
            return false;
            
        $this->_memcache=new Memcache;

        return $this->_memcache->connect($options['host'],$options['port']);
    }

    public function set($key ,$value,$ttl=null){
        return $this->_memcache->set($key,$value,MAMCACHE_COMPRESSED,$ttl);
    }
    
    public function & get($key){
        return $this->_memcache->get($key);
    }
    
    public function clear(){
        return $this->_memcache->flush();
    }
    
    public function del($key){
        return $this->_memcache->delete($key);
    }
    
    public function status(){
        return $this->_memcache->getStats();
    }
    
    public function getMc(){
        return $this->_memcache;
    }
    
}